package org.sxf.app.sign.utils;


import java.security.MessageDigest;

/**
 * Created by mhy8958 on 2015/5/20.
 */
public class MD5Utils {
    public final static String MD5(String s){
        char hexDigits[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        try{
            byte[] input = s.getBytes();
            MessageDigest mdInstance = MessageDigest.getInstance("MD5");
            mdInstance.update(input);
            byte[] md = mdInstance.digest();
            int length = md.length;
            char str[] = new char[length*2];
            int i = 0;
            for(int j = 0;j<length;j++){
                byte b = md[j];
                str[i++] = hexDigits[b >>> 4 & 0xf];
                str[i++] = hexDigits[b & 0xf];
            }
            return new String(str);
        }catch (Exception e){
            //  e.printStackTrace();
            return null;
        }
    }
}
